package com.study.suanfa;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @description: QueueTest   两个队列模拟堆栈
 * @date: 2020/11/11 19:32
 * @author: hcm
 * @version: 1.0
 */
public class QueueTest {
    public static void main(String[] args) {

        //队列1
        Queue<String> queue1 = new LinkedList<>();

        //队列2
        Queue<String> queue2 = new LinkedList<>();

        ArrayList<String> list = new ArrayList<>();

        //往队列添加元素
        queue1.offer("a");
        queue1.offer("b");
        queue1.offer("c");
        queue1.offer("d");
        queue1.offer("e");
        System.out.println("进栈：");

        //队列依次加入list集合之中

        for (String q : queue1){
            list.add(q);
            System.out.println(q);
        }

        //倒序取出
        for (int size = list.size()-1; size >= 0; size--) {
            queue2.offer(list.get(size));
        }
        //打印队列
        System.out.println("");
        System.out.println("出栈：");

        for (String s : queue2) {
            System.out.println(s);
        }


    }

    //栈，先进后出


}
